// pages/allDetail/allDetail.js
// pages/w-get-detail/w-get-detail.js
let http = require('../../utils/request.js')
let path = getApp().globalData.path
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: '待收货',
    baseurl: path,
    time: '',
  },
  // 订单支付
  order_pay(e) {
    let _this = this
    let orderid = _this.data.orderid
    http.postHttp('/user_order_pay', {
      order_id: orderid
    }, {
      token: wx.getStorageSync('token')
    }).then(res => {
      wx.requestPayment({
        timeStamp: res.data.data.timeStamp,
        nonceStr: res.data.data.nonceStr,
        package: res.data.data.package,
        signType: 'MD5',
        paySign: res.data.data.paySign,
        success(res) {
          console.log('支付成功')
          wx.redirectTo({
            url: '/pages/orderCenter/orderCenter',
          })
        },
        fail(res) {}
      })
    })
  },
  // 确认收货
  goConfirm(e) {
    let orderid = _this.data.orderid
    http.postHttp('/user_order_status', {
      order_id: orderid,
      status: 3
    }, {
      token: wx.getStorageSync('token')
    }).then(res => {
      console.log(res, '确认收货')

    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let orderid = options.orderid
    http.getHttp('/user_order_detail', {
      order_id: orderid
    }, {}).then(res => {
      console.log('tmpDetail', res)
      if(res.data.data.end_time){
        let time=res.data.data.end_time
        var timestamp = Date.parse(new Date());
        console.log("当前时间戳为：" + timestamp);
        let timeResult = (time * 1000 - timestamp)
        this.setData({
          time: timeResult,
          tmp: res.data.data,
        })
      }
      
      if (res.data.code == 1) {
        this.setData({
          tmp: res.data.data,
          
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})